$(function() {   
    $("#mensaje").fadeOut(3000);
    $("#mensajesUsuario").delay(4000).fadeOut('normal');
    $(".soloNumeros").keypress(function(evt) {
        var charCode = (evt.which) ? evt.which : evt.keyCode;
        if ((charCode > 47 && charCode < 58) || charCode == 8 || charCode == 13 || charCode == 9)
            return true;
        return false;
    });

    $(".soloNumerosSignoMenos").keypress(function(evt) {
        var charCode = (evt.which) ? evt.which : evt.keyCode;
        if ((charCode > 47 && charCode < 58) || charCode == 8 || charCode == 13 || charCode == 9 || charCode == 45 || charCode == 46)
            return true;
        return false;
    });

    $(".formBlockDisplay").submit(function(e) {
        $("#coverDisplay").css({
            "opacity": "1",
            "width": "100%",
            "height": "100%"
        });
    });


    $(".datePicker").datepicker({
        changeMonth: true,
        changeYear: true,
        dateFormat: "mm/dd/yy",
        monthNamesShort: ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"],
        dayNamesMin: ["Dom", "Lun", "Mar", "Mié", "Juv", "Vie", "Sáb"]
    });


    $("#botonCancelarReserva").click(function(e) {
        $("#modalEliminarReserva").modal();
    });
    $("#enviarFormEliminarReserva").click(function(e) {
        $("#formEliminarReserva").submit();
    });

});
$("#nuevaTemporada").on("click", nTClick);
$("#nuevoPeriodo").on("click", nPClick);

function nTClick(e)
{
    e.preventDefault();
    $("#clonarTemporada").append("<br> <div class='row-fluid'> <div class='row-fluid'> <div class='span12 titulo'> <div class='span4 offset4'><label class='pull-left'><b>Predeterminada</b> <button type='button' class='btn btn-mini btn-inverse'>Cambiar nombre</button> <button type='button' class='btn btn-mini btn-inverse'>Eliminar</button></label></div> </div> </div> <div class='row-fluid'> <div class='span12 contenido'> <div class='row-fluid'> <div class='span2'><label class='pull-right'>Desde:</label></div> <div class='span2'><div class='input-prepend'> <span class='add-on'><i class='icon-calendar'></i></span> <input type='text' class='datePicker input-small'> </div> </div> <div class='span2'><label class='pull-right'>Hasta:</label></div> <div class='span2'><div class='input-prepend'> <span class='add-on'><i class='icon-calendar'></i></span> <input type='text' class='datePicker input-small'> </div> </div> <div class='span2 offset1'><label class='pull-right'><button type='submit' class='btn btn-mini btn-inverse'>Eliminar periodo </button></label></div> </div> <br> <div class='row-fluid'> <div class='span2 offset2'><button type='submit' class='btn btn-mini btn-inverse'>Nuevo periodo </button></div> </div> </div> </div> </div>");



}
function nPClick(e)
{
    e.preventDefault();
    var i = $(this).attr("data-i");
    // alert(i);
    $("#clonarPeriodo").append("<br><div class='row-fluid'> <div class='span2'><label class='pull-right'>Desde:</label></div> <div class='span2'><div class='input-prepend'> <span class='add-on'><i class='icon-calendar'></i></span> <input type='text' class='datePicker input-small'> </div> </div> <div class='span2'><label class='pull-right'>Hasta:</label></div> <div class='span2'><div class='input-prepend'> <span class='add-on'><i class='icon-calendar'></i></span> <input type='text' class='datePicker input-small'> </div> </div> <div class='span2 offset1'><label class='pull-right'><button type='submit' class='btn btn-mini btn-inverse'>Eliminar periodo </button></label></div></div><br>");



}


$(".ayuda").click(function() {
    return false;
});
function validarFormulario(idFormulario) {

    var flag = true;
    $("#" + idFormulario + " .error").remove();
    $("#" + idFormulario + " .requerido").each(function() {

        var elemento = this;
        if (elemento.value == "") {
            $(this).focus();
            $(this).before("<span class='error'>*</span>")
            flag = false;
            return false;
        }
    });
    return flag;
}
function validarFormularioAfter(idFormulario) {

    var flag = true;
    $("#" + idFormulario + " .error").remove();
    $("#" + idFormulario + " .requerido").each(function() {

        var elemento = this;
        if (elemento.value == "") {
            $(this).focus();
            $(this).after("<span class='error'>*</span>")
            flag = false;
            return false;
        }
    });
    return flag;
}

function validarFormularioAfter(idFormulario) {

    var flag = true;
    $("#" + idFormulario + " .error").remove();
    $("#" + idFormulario + " .requerido").each(function() {

        var elemento = this;
        if (elemento.value == "") {
            $(this).focus();
            $(this).after("<span class='error'>*</span>")
            flag = false;
            return false;
        }
    });

    return flag;
}
